<% session[:return_to] = session[:ret_post] = nil %>
<% session[:post_id] = nil %>
<h2>Forum</h2>

<% @categories.each do |c| %>
  <% if c.parent_id.nil? %>
    <hr/>
    <% if c.user_level_rule.view_level_id >= get_user_level(session[:user_id]) %>
      <% posts = get_category_posts(c.id) %>
      <span class="category"><%= link_to( c.name, show_category_posts_path(c.id) ) %></span>

      <ul class="forum">
        <%= render :partial => "posts/category_index", :locals => { :posts => posts } %>

        <% if !c.children.nil? %>
          <% c.children.each do |cc| %>
            <% posts = get_category_posts(cc.id) %>
            <li class="category"><%= link_to( cc.name, show_category_posts_path(cc.id) ) %></li>
            <ul class="forum">
              <%= render :partial => "posts/category_index", :locals => { :posts => posts } %>
            </ul>
          <% end %>

        </ul>
      <%  end %>
    <% end %>
  <% end %>
<% end  %>
<hr/>